package com.mpyy.handler.purchase;

import com.alibaba.fastjson.JSON;
import com.mpyy.pojo.AddSupplierType;
import com.mpyy.pojo.DepotInfo;
import com.mpyy.pojo.InventoryDesc;
import com.mpyy.pojo.SupplierInfo;
import com.mpyy.service.purchase.PurchaseReturnServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * @version 1.0
 * @Description PurchaseReturnHandler
 * @Author liangxinyu
 * @Date 2022-03-09 14:08
 */
@Controller
public class PurchaseReturnHandler {
    @Autowired
    @Qualifier(value = "purchaseReturnServiceImpl")
    private PurchaseReturnServiceInter purchaseReturnServiceInter;

    /* 供货商信息查询 */
    @RequestMapping(value = {"/searchSupplierInfo"})
    @ResponseBody
    public String searchSupplierInfo(){
        List<SupplierInfo> supplierInfos = purchaseReturnServiceInter.searchSupplierInfo();
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("code",0);
        objectObjectHashMap.put("msg","");
        objectObjectHashMap.put("count",supplierInfos.size());
        objectObjectHashMap.put("data",supplierInfos);
        return JSON.toJSONString(objectObjectHashMap);
    }

    /* 出货仓库 */
    @RequestMapping(value = {"/purchaseReturn"})
    @ResponseBody
    public String searchDepotInfo(){
        List<DepotInfo> depotInfos = purchaseReturnServiceInter.searchDepotInfo();
        return JSON.toJSONString(depotInfos);
    }

    /* 添加退货商品 */
    @RequestMapping(value = {"/addReturnedInfoBtn/{depotId}"})
    @ResponseBody
    public String addReturnedInfoBtn(HttpServletRequest req, @PathVariable("depotId") String did){
        System.out.println("did" + did);
        List<InventoryDesc> inventoryDescs = purchaseReturnServiceInter.addReturnedInfoBtn(did);
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("code",0);
        objectObjectHashMap.put("msg","");
        objectObjectHashMap.put("count",inventoryDescs.size());
        objectObjectHashMap.put("data",inventoryDescs);
        return JSON.toJSONString(objectObjectHashMap);
    }

    /* 供货商信息查询 */
    @RequestMapping(value = {"/searchSupplierType"})
    @ResponseBody
    public String searchSupplierType(){
        List<AddSupplierType> addSupplierTypes = purchaseReturnServiceInter.searchSupplierType();
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("code",0);
        objectObjectHashMap.put("msg","");
        objectObjectHashMap.put("count",addSupplierTypes.size());
        objectObjectHashMap.put("data",addSupplierTypes);
        return JSON.toJSONString(objectObjectHashMap);
    }

    /* 供货商类型 + 默认选择 */
    @RequestMapping(value = {"/doUpdateSupplierType"},method = RequestMethod.PUT)
    @ResponseBody   // 如果要返回数据到页面就need这个注解
    public void doUpdateSupplierType(String supType,String defaultSetting){
        AddSupplierType addSupplierType = new AddSupplierType();
        addSupplierType.setSupType("101" + supType);
        addSupplierType.setSupType(supType);
        addSupplierType.setDefaultSetting(defaultSetting);
        int i = purchaseReturnServiceInter.doUpdateSupplierType(addSupplierType);
    }
}
